import axios from "axios";

export default {
  namespaced: true,
  state: {
    tableData: [],
  },
  getters: {},
  mutations: {
    SET_TABLE_DATA(state, data) {
      state.tableData = data;
    },
  },
  actions: {
    async getTableData(context) {
      const res = await axios({
        url: "http://120.27.209.174:1010/api/v1/posts",
      });
      context.commit("SET_TABLE_DATA", res.data.data);
    },
    async deleteArticle({ dispatch }, id) {
      await axios({
        method: "DELETE",
        url: `http://120.27.209.174:1010/api/v1/posts/${id}`,
      });
      dispatch("getTableData");
    },
  },
};
